package com.ict.dataprocess;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import com.ict.config.Config;
import com.ict.utils.CacheObject;
import com.ict.utils.ConnMQUtil;
import com.ict.utils.ConnRedisUtil;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.ShutdownSignalException;

import team.iOceanPlus.PB.Target;

public class OrigReceiveMainMQThread extends Thread {
	public void run() {
        /**一次接受10个PB，已list方式存入redis中*/
		while(true) {
			String[] arrRoutingKey = {Config.origTargetRoutingKey};
			ConnMQUtil connMQUtil = new ConnMQUtil();
			try {
				QueueingConsumer.Delivery delivery = connMQUtil.recv("topic", Config.recvExChangeName, arrRoutingKey, "xgs_tap_by_tlc");
				String message = new String(delivery.getBody());
				byte [] bytmessage=delivery.getBody();
				Target.PBTarget test= Target.PBTarget.parseFrom(bytmessage);
				System.out.println(test.getListTargetPosList().get(0).getEnumTargetInfoTypeValue());
				
				//ConnRedisUtil.jedis.hset("recv_orig_pb".getBytes(), ("field"+x).getBytes(), bytmessage);
				//ConnRedisUtil.jedis.lpush("recv_orig_pb".getBytes(), bytmessage);
				UUID  uuid=UUID.randomUUID();
				//System.out.println(uuid.toString());
				//ConnRedisUtil.jedis.hset("recv_orig_pb".getBytes(), (uuid.toString()).getBytes(), bytmessage);
				List<byte []>   lstMessage=new  ArrayList<byte  []>();
				//lstMessage.add(bytmessage);
				//CacheObject.lstBytCache.add(bytmessage);
				//System.out.println(uuid.toString());
				//Target.PBTarget info = Target.PBTarget.parseFrom(delivery.getBody());
				//ConnMQUtil.recvChannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
			} catch (ShutdownSignalException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ConsumerCancelledException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

}
